package com.reny.ll.git.core

import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding

abstract class RBaseActivity<VB : ViewDataBinding> : AppCompatActivity() {

    lateinit var binding: VB
    abstract val layoutId: Int

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        afterOnCreate()

        binding = DataBindingUtil.setContentView(this, layoutId)

        lifecycle.addObserver(delegateImp)
    }

    override fun onRequestPermissionsResult(
        requestCode: Int,
        permissions: Array<out String>,
        grantResults: IntArray
    ) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults)
        delegateImp.onRequestPermissionsResult(requestCode, permissions, grantResults)
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        delegateImp.onActivityResult(requestCode, resultCode, data)
    }

    override fun onTrimMemory(level: Int) {
        super.onTrimMemory(level)
        delegateImp.onTrimMemory(level)
    }

    override fun onLowMemory() {
        super.onLowMemory()
        delegateImp.onLowMemory()
    }

    abstract val delegateImp: BaseDelegate

    open fun afterOnCreate(){

    }

}